import { PetForgeType } from "./PetForgeType";
import { ItemConfig } from "../../resource/ItemConfig";
import { JSON } from "../../../../com/mui/serialization/json/JSON";
import { TItemUpdate } from "../../../../Message/Db/Tables/TItemUpdate";
import { GameDefConfig } from "../../resource/GameDefConfig";
import { EPrictUnit } from "../../../../Message/Public/EPrictUnit";
import { Cache } from "../../cache/Cache";
type int = number;
//class PetForgeItemUpdate
    
    export  class PetForgeItemUpdate
    {
        

        public static getItemUpdate(arg1: string, arg2: int): Object
        {
            var loc1=null;
            if (arg1 != PetForgeType.petRefine) 
            {
                if (arg1 == PetForgeType.upgrade) 
                {
                    loc1 = ItemConfig.instance.getPetUpdateInfo(ItemConfig.StrengthPetSpirit, arg2);
                }
            }
            else 
            {
                loc1 = ItemConfig.instance.getPetUpdateInfo(ItemConfig.RefreshPetGrowth, arg2);
            }
            return loc1;
        }

        public static getConditionByBlessValue(arg1: string, arg2: int): Map<any, any> /* flash.utils.Dictionary */
        {
            var loc2=null;
            var loc3=null;
            var loc4=null;
            var loc5=0;
            var loc1=new Map<any, any> /* flash.utils.Dictionary */();
            if (arg1 != PetForgeType.petRefine) 
            {
                if (arg1 == PetForgeType.upgrade) 
                {
                    loc2 = ItemConfig.instance.getItemUpdateArrayByOperation("StrengthPetSpirit");
                }
            }
            else 
            {
                loc2 = ItemConfig.instance.getItemUpdateArrayByOperation("RefreshPetGrowth");
            }
            var loc6=0;
            while (loc6 < loc2.length) 
            {
                loc3 = loc2[loc6];
                loc4 = JSON.deserialize(loc3.condition);
                loc5 = int(loc4.blessValue);
                if (arg2 < loc5) 
                {
                    loc1["current"] = JSON.deserialize((loc2[(loc6 - 1)] as TItemUpdate).condition);
                    loc1["next"] = loc4;
                    break;
                }
                if (loc6 == (loc2.length - 1) && loc1["next"] == null) 
                {
                    loc1["current"] = loc4;
                    loc1["next"] = loc4;
                }
                ++loc6;
            }
            return loc1;
        }

        public static getMiniAbleBless(arg1: string): int
        {
            var loc1=0;
            var loc2=null;
            var loc3=null;
            var loc4=null;
            var loc5=0;
            if (arg1 != PetForgeType.petRefine) 
            {
                if (arg1 == PetForgeType.upgrade) 
                {
                    loc2 = ItemConfig.instance.getItemUpdateArrayByOperation("StrengthPetSpirit");
                }
            }
            else 
            {
                loc2 = ItemConfig.instance.getItemUpdateArrayByOperation("RefreshPetGrowth");
            }
            var loc6=0;
            while (loc6 < loc2.length) 
            {
                loc3 = loc2[loc6];
                loc4 = JSON.deserialize(loc3.condition);
                if ((loc5 = int(loc4.blessValue)) > 0) 
                {
                    loc1 = loc5;
                    break;
                }
                ++loc6;
            }
            return loc1;
        }

        public static haveEnoughMoney(arg1: string, arg2: int): Boolean
        {
            var loc1=false;
            var loc2=PetForgeItemUpdate.getItemUpdate(arg1, arg2);
            var loc3=0;
            var loc4=0;
            if (loc2) 
            {
                loc3 = loc2.cost;
                loc4 = loc2.unit;
            }
            return PetForgeItemUpdate.playerHaveEnoughMoney(loc4, loc3);
        }

        public static getCost(arg1: string, arg2: int): int
        {
            var loc1=PetForgeItemUpdate.getItemUpdate(arg1, arg2);
            var loc2=0;
            if (loc1) 
            {
                loc2 = int(loc1.cost);
            }
            return loc2;
        }

        public static getForgeCostUnitName(arg1: string, arg2: int): string
        {
            var loc1="";
            var loc2=PetForgeItemUpdate.getItemUpdate(arg1, arg2);
            var loc3=0;
            if (loc2) 
            {
                loc3 = loc2.unit;
            }
            loc1 = GameDefConfig.instance.getEPrictUnitImg(loc3);
            return loc1;
        }

        public static getForgeCost(arg1: string, arg2: int): Map<any, any> /* flash.utils.Dictionary */
        {
            var loc1=new Map<any, any> /* flash.utils.Dictionary */();
            var loc2="";
            var loc3=PetForgeItemUpdate.getItemUpdate(arg1, arg2);
            var loc4=0;
            var loc5=0;
            if (loc3) 
            {
                loc5 = loc3.cost;
                loc4 = loc3.unit;
            }
            loc2 = GameDefConfig.instance.getEPrictUnitImg(loc4);
            loc1["unitName"] = loc2;
            loc1["unit"] = loc4;
            loc1["cost"] = loc5;
            return loc1;
        }

        public static playerHaveEnoughMoney(arg1: int, arg2: int): Boolean
        {
            var loc1=false;
            var loc2=arg1;
            switch (loc2) 
            {
                case EPrictUnit._EPriceUnitCoin:
                {
                    if (Cache.instance.role.money.coin + Cache.instance.role.money.coinBind >= arg2) 
                    {
                        loc1 = true;
                    }
                    break;
                }
                case EPrictUnit._EPriceUnitCoinBind:
                {
                    if (Cache.instance.role.money.coin + Cache.instance.role.money.coinBind >= arg2) 
                    {
                        loc1 = true;
                    }
                    break;
                }
                case EPrictUnit._EPriceUnitGold:
                {
                    if (Cache.instance.role.money.gold >= arg2) 
                    {
                        loc1 = true;
                    }
                    break;
                }
                case EPrictUnit._EPriceUnitGoldBind:
                {
                    if (Cache.instance.role.money.goldBind >= arg2) 
                    {
                        loc1 = true;
                    }
                    break;
                }
            }
            return loc1;
        }
    }
